import 'package:flutter/material.dart';

import '../core/app_export.dart';

class GenderSelection extends StatefulWidget {
  final String? title;
  final Function(int) onChanged;
  final int value;

  const GenderSelection({super.key, required this.onChanged, this.title, required this.value});

  @override
  State<GenderSelection> createState() => _GenderSelectionState();
}

class _GenderSelectionState extends State<GenderSelection> {
  int selectedValue = 0;

  @override
  void initState() {
    selectedValue = widget.value;
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        if(widget.title != null)
          Align(
            alignment: Alignment.centerRight,
            child: Padding(
              padding: const EdgeInsets.all(4.0),
              child: Text(widget.title!,style: theme.textTheme.bodySmall!.copyWith(fontSize: 16),),
            ),
          ),
        Container(
          padding: const EdgeInsets.all(4.0),
          decoration: BoxDecoration(
            color: Colors.transparent,
            border: Border.all(color: Colors.grey),
            borderRadius: BorderRadius.circular(8.0),
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              GestureDetector(
                onTap: () {
                  setState(() {
                    selectedValue = 0;
                  });
                  widget.onChanged(selectedValue);
                },
                child: Container(
                  padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(8.0),
                    border: Border.all(
                      color: selectedValue == 0 ? Colors.orange : Colors.transparent,
                      width: 2.0,
                    ),
                  ),
                  child: Text(
                    'ذكر',
                    style: TextStyle(
                      color: selectedValue == 0 ? Colors.orange : theme.textTheme.labelSmall?.color,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
              GestureDetector(
                onTap: () {
                  setState(() {
                    selectedValue = 1;
                  });
                  widget.onChanged(selectedValue);
                },
                child: Container(
                  padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(8.0),
                    border: Border.all(
                      color: selectedValue == 1 ? Colors.orange : Colors.transparent,
                      width: 2.0,
                    ),
                  ),
                  child: Text(
                    'أنثى',
                    style: TextStyle(
                      color: selectedValue == 1 ? Colors.orange : theme.textTheme.labelSmall?.color,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}